{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户基本信息界面</title>
    <!-- 引入 layui.css -->
    <link href="{%static '/css/layui.css'%}" rel="stylesheet">
    <link href="{%static '/css/font-awesome.min.css'%}" rel="stylesheet">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span >用户名</span>
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name" name="user_name" required="" lay-verify="required" autocomplete="off" class="layui-input" value="{{user_name}}" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span >姓名</span>
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="fullname" name="fullname" required="" lay-verify="required" autocomplete="off" class="layui-input " value="{{full_name}}" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span >邮箱</span>
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="email" name="email" required="" lay-verify="required" autocomplete="off" class="layui-input " value="{{email}}" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span >电话</span>
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="mobile" name="mobile" required="" lay-verify="required" autocomplete="off" class="layui-input " value="{{mobile}}" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span >地址</span>
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="address" name="address" required="" lay-verify="required" autocomplete="off" class="layui-input " value="{{address}}" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                  <input type="radio" name="sex" value="M" title="男" {{sex_male}}>
                  <input type="radio" name="sex" value="F" title="女" {{sex_fmale}}>
                </div>
              </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span >状态</span>
                </label>
                <div class="layui-input-block">
                    <input type="checkbox" name="is_active" value="true" title="启用" {{is_active}}>
                </div>
            </div>
        </div>
        <button type="button" id="btn_ok" class="layui-btn">保存</button>
    </div>

<script src="{%static '/js/layui.min.js'%}" charset="utf-8"></script>
<script>
    layui.use(['layer','jquery','table','form'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            table = layui.table,
            form = layui.form;


        $("#btn_ok").click(function(){
           email = $("#email").val()
           mobile = $("#mobile").val()
           address = $("#address").val()
           user_name = $("#user_name").val()
           full_name = $("#fullname").val()
           sex = $("input[name='sex']:checked").val();

           is_active = $("input[name='is_active']:checked").val();

           url="/api/user/staruser/{{user_id}}/"
           $.ajax({
               url:url,
               type:'put',
               data:{
                   "email":email,
                   "mobile":mobile,
                   "address":address,
                   "username":user_name,
                   "fullname":full_name,
                   "sex":sex,
                   "is_active":is_active
               },
               dataType:"json",
               success:function(res){
                   if(res.code==200){
                       layer.msg(res.msg,{icon:1,time:1*1000,shade:0.4},function(){
                           location.href="/index";
                       });
                   }
                   else{
                       layer.msg(res.msg,{time:1*1000});
                   }
               },
               error:function(err){
                   layer.msg("修改出错",{time:1*1000});
               }
           });
        });
    });
</script>
</body>
</html>